package boun.center;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;

public class CalendarEvent implements Serializable {
    private static final long serialVersionUID = 1L;
    private Calendar beginDate, endDate;
	private ArrayList<String> descriptions;
	
	public CalendarEvent() {
		descriptions = new ArrayList<String>();
		beginDate = Calendar.getInstance();
		endDate = Calendar.getInstance();
	}
	
	public void setDates(String str) {
		if (str.indexOf('-') == -1) {
			String nums[] = str.split("\\.");
			int year = Integer.parseInt(nums[2].trim());
			int month = Integer.parseInt(nums[1].trim()) - 1;
			int day = Integer.parseInt(nums[0].trim());
			beginDate.set(year, month, day);
			endDate.set(year, month, day);
		} else {
			if (str.split("-").length > 2) {//5-6-8.8.2011
				String nums[] = str.split("(-|\\.)");
				int n = nums.length;
				int year = Integer.parseInt(nums[n - 1].trim());
				int month = Integer.parseInt(nums[n - 2].trim()) - 1;
				int endDay = Integer.parseInt(nums[n - 3].trim());
				int beginDay = Integer.parseInt(nums[0].trim());
				beginDate.set(year, month, beginDay);
				endDate.set(year, month, endDay);
			} else if ((str.split("-")[0]).indexOf('.') == -1) { // 17-22.3.2011
				String nums[] = str.split("(-|\\.)");
				int year = Integer.parseInt(nums[3].trim());
				int month = Integer.parseInt(nums[2].trim()) - 1;
				int endDay = Integer.parseInt(nums[1].trim());
				int beginDay = Integer.parseInt(nums[0].trim());
				beginDate.set(year, month, beginDay);
				endDate.set(year, month, endDay);
			} else {// 9.05-7.06.2011
				String nums[] = str.split("(-|\\.)");
				int year = Integer.parseInt(nums[4].trim());
				int beginMonth = Integer.parseInt(nums[1].trim()) - 1;
				int endMonth = Integer.parseInt(nums[3].trim()) - 1;
				int endDay = Integer.parseInt(nums[2].trim());
				int beginDay = Integer.parseInt(nums[0].trim());
				beginDate.set(year, beginMonth, beginDay);
				endDate.set(year, endMonth, endDay);
			}
		}
	}
	
	public void addDescription(String desc) {
		descriptions.add(desc);
	}
	
	public Calendar getBeginDate() {
		return beginDate;
	}
	public Calendar getEndDate() {
		return endDate;
	}
	public ArrayList<String> getDescriptions() {
		return descriptions;
	}

}
